#pragma once
#ifndef IO_BINARYWRITER_H
#define IO_BINARYWRITER_H
//------------------------------------------------------------------------------
/**
    @class Core::BinaryWriter
    
    A friendly interface for writing binary data to a stream. Optionally
    the writer can use memory mapping for optimal write performance.
    
    @todo convert endianess!    
    
    (C) 2006 Radon Labs GmbH
*/
#include "streamwriter.h"


//------------------------------------------------------------------------------
namespace GBase
{
	class BinaryWriter : public StreamWriter
	{
	public:
		/// constructor
		BinaryWriter();
		/// destructor
		virtual ~BinaryWriter();
		/// call before Open() to enable memory mapping (if stream supports mapping)
		void SetMemoryMappingEnabled(bool b);
		/// return true if memory mapping is enabled
		bool IsMemoryMappingEnabled() const;
		
		/// begin reading from the stream
		virtual bool Open();
		/// end reading from the stream
		virtual void Close();
		/// write an 8-bit char to the stream
		void WriteChar(char c);
		/// write an 8-bit unsigned char to the stream
		void WriteUChar(unsigned char c);
		/// write an 16-bit short to the stream
		void WriteShort(short s);
		/// write an 16-bit unsigned short to the stream
		void WriteUShort(unsigned short s);
		/// write an 32-bit int to the stream
		void WriteInt(int i);
		/// write an 32-bit unsigned int to the stream
		void WriteUInt(unsigned int i);
		/// write a float value to the stream
		void WriteFloat(float f);
		/// write a double value to the stream
		void WriteDouble(double d);
		/// write a boolean value to the stream
		void WriteBool(bool b);
		/// write a 64-bit long value to the stream
		void WriteLLong(long long l);
		/// write a 64-bit unsigned long value to the stream
		void WriteULLong(unsigned long long l);
		//write a string
		void WriteString1024(const char* txt);
		/// write raw data
		void WriteRawData(const void* ptr, unsigned int numBytes);

	public:
		bool enableMapping;
		bool isMapped;
		//System::ByteOrder byteOrder;
		unsigned char* mapCursor;
		unsigned char* mapEnd;
	};

	//------------------------------------------------------------------------------
	/**
	*/
	inline
	void
	BinaryWriter::SetMemoryMappingEnabled(bool b)
	{
		this->enableMapping = b;
	}

	//------------------------------------------------------------------------------
	/**
	*/
	inline
	bool
	BinaryWriter::IsMemoryMappingEnabled() const
	{
		return this->enableMapping;
	}
	

} // namespace Core
//------------------------------------------------------------------------------
#endif
